package com.liu.yupao.config;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author lqh
 * @since 2025-11-10 22:20
 * 提供HttpSession给websocket使用
 * 为什么继承了这个类之后 没有需要实现的类？
 * 答：因为这个继承的这个类没有抽象方法
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake (ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取httpSession对象
        HttpSession httpSession = (HttpSession) request.getHttpSession ();
        //将Httpsession保存起来
        sec.getUserProperties ().put (httpSession.getClass ().getName (), httpSession);
    }
}
